// pages/index/index.js
import {getCategoryList} from '../../apis/index';
import {getGoodsList} from '../../apis/index'
Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 500,
    CategoryList:[],
    goodList:[],
    cateIndex:0,
    goodsList: [] , //商品列表数据
    show: false
  },
  onLoad(options) {
    wx.showLoading({
      title: '亲，没有更多了',
    })
    this.initData()
  },
  categoryID(e){
    //获取商品详情的商品id
    console.log(e.currentTarget.dataset.id)
    this.setData({
      cateIndex:e.currentTarget.dataset.id
    })
    wx.request({
      url: 'http://192.168.76.39/index.php?s=/api/goods/list',
      data: {
        categoryId: e.currentTarget.dataset.id,
      },
      success: res => {
        console.log(res.data.data.list.data)
        this.setData({
         goodList : res.data.data.list.data,
        })
      }
    })
  },
  async initData(){
    const res = await getCategoryList()
    console.log("获取到的后台数据是", res)
    const categoryData = res.data
    const categoryListData = categoryData.list
    console.log("分类列表", categoryListData)
    this.setData({
      CategoryList: categoryListData
    })
    const res1 = await getGoodsList()
    console.log(res1)
    const goodsList = res1.data.list.data
    this.setData({
      goodsList:goodsList
    })
    wx.hideLoading()
  },
  shoppDetail(e){
    //获取商品详情的商品id
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../index/detail/index?goodsId='+e.currentTarget.dataset.id,
    })
  },
  seachShopp(){
    wx.navigateTo({
      url: '/pages/seach/index',
    })
  },
  changeId(){
    this.setData({
      cateIndex:0
    })
  }
})